package com.javasm.transfer.goodsTransfer;

import com.javasm.domin.entity.goodsEntity.GdBrand;
import com.javasm.domin.entity.goodsEntity.GdColour;
import com.javasm.domin.entity.goodsEntity.GdGoods;
import com.javasm.domin.entity.goodsEntity.GdType;
import com.javasm.domin.vo.goodsVo.GdColourVo;
import com.javasm.domin.vo.goodsVo.GoodsVo;
import com.javasm.mapper.goodsMapper.GdBrandMapper;
import com.javasm.mapper.goodsMapper.GdColourMapper;
import com.javasm.mapper.goodsMapper.GdGoodsMapper;
import com.javasm.mapper.goodsMapper.GdTypeMapper;
import com.javasm.transfer.base.BaseTransfer;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author：zzt
 * @Version：1.0
 * @Date：2021/11/19-15:46
 * @Since:jdk1.8
 * @Description:
 */
@Component
@RequiredArgsConstructor
public class GdGoodsTransfer extends BaseTransfer<GdGoods, GoodsVo> {


    private final GdGoodsMapper gdGoodsMapper;
    private final GdTypeMapper gdTypeMapper;
    private final GdColourMapper gdColourMapper;
    private final GdBrandMapper gdBrandMapper;


    public List<GoodsVo> set(List<GdGoods> list){

        //先转成vo对象
        List<GoodsVo> goodsVos = super.toVO(list);

        //遍历vo对象
        for (int i = 0; i < goodsVos.size(); i++) {
            //拿到entity对象
            GdGoods gdGoods = list.get(i);
            //拿到good对象中的id
            //品牌id
            Integer brandId = gdGoods.getBrandId();
            GdBrand gdBrand = gdBrandMapper.selectById(brandId);
            //颜色id
            Integer colourId = gdGoods.getColourId();
            GdColour gdColour = gdColourMapper.selectById(colourId);
            //类型id
            Integer typeId = gdGoods.getTypeId();
            GdType gdType = gdTypeMapper.selectById(typeId);
            GoodsVo goodsVo = goodsVos.get(i);
            //判断是否为空进行赋值
            goodsVo.setBrandName(gdBrand==null?"":gdBrand.getBrandName());
            goodsVo.setColourName(gdColour==null?"":gdColour.getColourName());
            goodsVo.setTypeName(gdType==null?"":gdType.getTypeName());


        }
        return goodsVos;
    }




}
